# 导入异步编程所需的模块
import asyncio

# 从llama_index.llms.openai模块导入OpenAI类
from llama_index.llms.openai import OpenAI

llm = OpenAI(model="gpt-4o-mini")


def sync_call():
    response = llm.complete("李白是谁?")
    print(response)


async def async_call():
    response = await llm.acomplete("杜甫是谁?")
    print(response)


async def concurrent_call():
    tasks = [
        llm.acomplete("白居易是谁?"),
        llm.acomplete("鲁迅是谁?"),
        llm.acomplete("李大钊是谁?"),
    ]
    responses = await asyncio.gather(*tasks)
    print(responses)


async def main():
    sync_call()
    await async_call()
    await concurrent_call()


if __name__ == "__main__":
    asyncio.run(main())
